/******************************************************************************
Paper: The Impact of Welfare on Intergroup Relations
Author: Akshay Dixit

IHDS: This .do file analyzes the IHDS 2011-12 data to produce:
	- Table S17 (Correlation between household wealth and practice of untouchability)
	- Table S46 (Comparing landed and landless households in Telangana and Andhra Pradesh)
	- Statistic on residential segregation for the "Caste and Social Insurance" section.
******************************************************************************/

clear all

gl data "$identity/data/ihds/ICPSR_36151"

*******************************************************************************
*** COMPARE LANDED/LANDLESS IN AP AND TELANGANA ***
*******************************************************************************

u "$data/DS0002/36151-0002-Data.dta", clear

*** Keep data on Andhra Pradesh/Telangana ***
keep if STATEID == 28

*** Outcome variables ***

g practice_untouchability = TR4A
replace practice_untouchability = 1 if TR4B == 1
lab var practice_untouchability "Practice untouchability"

ren TR4C experienced_untouchability
lab var experienced_untouchability "Experienced untouchability (SC only)"

*** Independent variables ***

* Land ownership
g land_owned = ((FM4A > 0 & FM4A != .) | (FM4B > 0 & FM4B != .) | (FM4C > 0 & FM4C != .))
replace land_owned = . if FM1 == .
lab var land_owned "Own land"

* Telangana districts 
	// Telangana was not a separate state at the time of the IHDS survey.
	// In 2014, the districts below became part of the newly-formed state.
g telangana = (DISTRICT == 2801 | DISTRICT == 2802 | DISTRICT == 2803 | DISTRICT == 2804 | DISTRICT == 2805 | DISTRICT == 2806 | DISTRICT == 2807 | DISTRICT == 2810)
count if telangana == 1
codebook IDPSU if telangana == 1
lab var telangana "Telangana"

* Interaction term
g telangana_land_owned = telangana * land_owned
lab var telangana_land_owned "Telangana * Own land"

* Caste
ren ID13 caste_category
replace caste_category = . if caste_category == 9

*** Compare difference between landed and landless in Telangana and Andhra Pradesh ***

cap erase "$analysis/ihds_untouchability.tex"

local caste practice_untouchability experienced_untouchability
foreach var of local caste {
	reg `var' telangana_land_owned telangana land_owned i.caste_category, vce(cluster IDPSU)
	outreg2 using "$analysis/ihds_untouchability.tex", append label nocons nor2 
}

cap erase "$analysis/ihds_untouchability.txt"

*******************************************************************************
*** ASSET OWNERSHIP AND PRACTICE OF UNTOUCHABILITY ***
*******************************************************************************

u "$data/DS0002/36151-0002-Data.dta", clear

*** Outcome variable ***

g practice_untouchability = TR4A
replace practice_untouchability = 1 if TR4B == 1

*** Independent variables ***

* Caste & religion
ren ID11 religion
replace religion = . if religion == 9

ren ID13 caste_category
replace caste_category = . if caste_category == 9

* Education
ren HHEDUC highest_adult_education

* HH assets
desc CG4 CG5 CG6 CG7 CG8 CGTV CG11 CG12 CG13 CG14 CG15 CG16 CG17 CG18 CG19 CG20 CG21 CG22 CG23 CG24 CG25 CG26 CG27 CG28 CG29
local assets CG4 CG5 CG6 CG7 CG8 CGTV CG11 CG12 CG13 CG14 CG15 CG16 CG17 CG18 CG19 CG20 CG21 CG22 CG23 CG24 CG25 CG26 CG27 CG28 CG29
foreach var of local assets {
	egen `var'_std = std(`var')
}

egen index_assets = rowmean(CG4_std CG5_std CG6_std CG7_std CG8_std CGTV_std CG11_std CG12_std CG13_std CG14_std CG15_std CG16_std CG17_std CG18_std CG19_std CG20_std CG21_std CG22_std CG23_std CG24_std CG25_std CG26_std CG27_std CG28_std CG29_std)

*** Regression ***

lab var practice_untouchability "Practice untouchability"
lab var highest_adult_education "Highest adult education in household"
lab var index_assets "Household asset index"

cap erase "$analysis/ihds_exploring_income_effect.tex"

areg practice_untouchability index_assets highest_adult_education i.caste_category i.religion, absorb(IDPSU) vce(cluster IDPSU)
outreg2 using "$analysis/ihds_exploring_income_effect.tex", keep(index_assets highest_adult_education) append label nocons nor2 tex

cap erase "$analysis/ihds_exploring_income_effect.txt"

*******************************************************************************
*** PREVALENCE OF CASTE SEGREGATION ***
*******************************************************************************

u "$data/DS0012/36151-0012-Data.dta", clear

g castes_mixed = (VG10 == 1)
replace castes_mixed = . if VG10 == .
tab castes_mixed	// Castes live separately in 62.82% areas

*******************************************************************************

clear



